<?php

class ResultJSON {
	
	/**
	 * @var assoc_array
	 */
	private $content;
	
	/**
	 * @param boolean $isError
	 * @param string $sessionID
	 * @param string $errorMessage
	 */
	function __construct($isError = false, $sessionID = '', $errorMessage = ''){
		$this->content = array();
		$this->content['iE'] = $isError;
		if($isError && $errorMessage != '') $this->content['eMsg'] = $errorMessage;
		if($sessionID != '') $this->content['sID'] = $sessionID;
	}
	
	/**
	 * Adds a key value pair to the JSON Object and returns a reference on itself.
	 * @param string $key
	 * @param $value
	 * @return ResultJSON
	 */
	function addItem($key, $value){
		$this->content[$key] = $value;
		return $this;
	}
	
	/**
	 * Generates a string containing the views JSONObject
	 * @return string
	 */
	function renderView(){
		return json_encode($this->content);
	}
}

?>